package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Date;

public class Statistic {
	Connection connect =null;
	PreparedStatement pstm=null;
	public int sumBookingByDate(Date date){
            int s = 0;
            connect = Connector.getConnect();
            try{
                pstm = connect.prepareStatement("Select count(id) from tblinfobook where date_rg = ?");
                pstm.setDate(1, date);
                ResultSet rs = pstm.executeQuery();
                if(rs.next()){
                    s = rs.getInt("count(id)");
                }
            }catch(SQLException e){
                e.printStackTrace();
            }
            return s;
        }
        public int sumCheckoutByDate(Date date){
            int s = 0;
            connect = Connector.getConnect();
            try{
                pstm = connect.prepareStatement("Select count(id) from tblinfobook where date_checkout =?");
                pstm.setDate(1, date);
                ResultSet rs = pstm.executeQuery();
                
                if(rs.next()){
                    s = rs.getInt("count(id)");
                }
            }catch(SQLException e){
                e.printStackTrace();
            }
            return s;
        }
        public int sumRevenueByDate(Date date){
            int s = 0;
            connect = Connector.getConnect();
            try{
                pstm = connect.prepareStatement("Select sum(total) as tt from tblinfobook where date_checkout = ?");
                pstm.setDate(1, date);
                ResultSet rs = pstm.executeQuery();
                
                if(rs.next()){
                    s = rs.getInt("tt");
                }
            }catch(SQLException e){
                e.printStackTrace();
            }
            return s;
        }
	
}
